package com.sc.nft.task;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.sc.nft.dao.EcologyHatchCollecionShareProfitConfDao;
import com.sc.nft.dao.EcologyHatchDaoIncomeConfDao;
import com.sc.nft.dao.EcologyHatchShareProfitDao;
import com.sc.nft.dao.MarketManagementDaoPoolDao;
import com.sc.nft.dto.EcologyHatchConfDao;
import com.sc.nft.dto.EcologyHatchIncomeConfDao;
import com.sc.nft.dto.UserEcologyHatchRecordsDao;
import com.sc.nft.entity.*;
import com.sc.nft.enums.EcologyHatchShareProfitTypeEnum;
import com.sc.nft.enums.EcologyIncomeTypeEnum;
import com.sc.nft.enums.RedisKeyEnum;
import com.sc.nft.exception.GlobalException;
import com.sc.nft.service.*;
import com.sc.nft.util.WeChatUtil;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 生态-结算-任务
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class EcologyIncomeTask {

    private final UserEcologyHatchIncomeService userEcologyHatchIncomeService;
    private final EcologyHatchDaoIncomeConfDao ecologyHatchDaoIncomeConfDao;
    /**
     * 生态节点持仓奖
     */
    @XxlJob("ecologyNodePositionAward")
    public void ecologyNodeTakePositionIncome() throws Exception {
        userEcologyHatchIncomeService.ecologyNodeTakePositionIncome();
    }


    /**
     * 生态培育奖  城主和生态节点
     * 1: 7天培育奖=近7天（周一至周日
     * 2: 30天培育奖=近30天（前30天）
     * @throws Exception
     */
    @XxlJob("ecologyCultivateIncomeNew")
    public void ecologyCultivateIncome() throws Exception {
        userEcologyHatchIncomeService.ecologyCultivateIncomeNew();
    }


    /**
     * 生态贡献奖 城主和生态节点
     * 统计维度 :
     * 1: 7天内(不包含当天的前7天)
     * 2: 30天内(不包含当天的前30天)
     * @throws Exception
     */
    @XxlJob("ecologyContributionIncomeNew")
    public void ecologyContributionIncomeNew() throws Exception {
        userEcologyHatchIncomeService.ecologyContributionIncomeNew();
    }

    /**
     * 社区网点生态贡献奖
     * 1: 7天内(不包含当天的前7天)
     * 2: 365天内(不包含当天的前365天)
     *
     * @throws Exception
     */
    @XxlJob("communityNetworkEcologicalCultivationAwardNew")
    public void communityNetworkEcologicalCultivationAwardNew() throws Exception {
        userEcologyHatchIncomeService.communityNetworkEcologicalCultivationAwardNew();
    }



    /**
     * 城市服务中心生态贡献奖
     * @throws Exception
     */
    @XxlJob("urbanServiceCenterEcologicalContributionNew")
    public void urbanServiceCenterEcologicalContributionNew() throws Exception {
        userEcologyHatchIncomeService.urbanServiceCenterEcologicalContributionNew();
    }



    /**
     * 城市服务中心培育奖发放
     * @throws Exception
     */
    @XxlJob("ecologicalCultivationOfUrbanServiceCenterNew")
    public void ecologicalCultivationOfUrbanServiceCenterNew() throws Exception {
        userEcologyHatchIncomeService.ecologicalCultivationOfUrbanServiceCenterNew();
    }

    /**
     * DAO-生态培育奖
     * 1: 上周(周一到周日)
     * 2: 365天内(不包含当天的前365天)
     * @throws Exception
     */
    @XxlJob("daoEcologyCultivateIncomeNew")
    public void daoEcologyCultivateIncomeNew() throws Exception {
        List<EcologyHatchDaoIncomeConf> list = ecologyHatchDaoIncomeConfDao.getListByStatusAndType(EcologyIncomeTypeEnum.DAO_CULTIVATION_AWARD, Boolean.TRUE);
        list.forEach(userEcologyHatchIncomeService::daoEcologyCultivateIncomePoints);
    }

    @XxlJob("backFlowDaoPointsNew")
    public void backFlowDaoPoints() throws Exception {
        List<EcologyHatchDaoIncomeConf> list = ecologyHatchDaoIncomeConfDao.getListByStatusAndType(EcologyIncomeTypeEnum.DAO_CULTIVATION_AWARD, Boolean.TRUE);
        list.forEach(userEcologyHatchIncomeService::backFlowDaoPoints);
    }



    /**
     * dao贡献奖
     * 统计维度 :
     * 1: 7天内(不包含当天的前7天)
     * 2: 365天内(不包含当天的前365天)
     * @throws Exception
     */
    @XxlJob("daoEcologyContributionIncomeNew")
    public void daoEcologyContributionIncomeNew() throws Exception {
        List<EcologyHatchDaoIncomeConf> list = ecologyHatchDaoIncomeConfDao.getListByStatusAndType(EcologyIncomeTypeEnum.DAO_CONTRIBUTION_AWARD, Boolean.TRUE);
        list.forEach(userEcologyHatchIncomeService::daoEcologyContributionIncomePoints);
    }

    /**
     * DAO-持仓奖
     * @throws Exception
     */
    @XxlJob("daoPositionBonusAwardNew")
    public void daoPositionBonusAwardNew() throws Exception {
        List<EcologyHatchDaoIncomeConf> list = ecologyHatchDaoIncomeConfDao.getListByStatusAndType(EcologyIncomeTypeEnum.DAO_POSITION_BONUS_AWARD, Boolean.TRUE);
        list.forEach(userEcologyHatchIncomeService::daoPositionBonusAwardPoints);
    }

    /**
     * 每份分账流入分账池
     * @throws Exception
     */
    @XxlJob("disposeShareProfitDaoPool")
    public void disposeShareProfitDaoPool() throws Exception {
        userEcologyHatchIncomeService.disposeShareProfitDaoPool();
    }

    /**
     * 分账池流入钱包
     * @throws Exception
     */
    @XxlJob("theDividingPoolFlowsIntoTheWallet")
    public void theDividingPoolFlowsIntoTheWallet() throws Exception {
        userEcologyHatchIncomeService.theDividingPoolFlowsIntoTheWallet();
    }


}
